app.factory("$token", ["$window", "$q", "$localStorage", "$timeout", "$rootScope", function ($window, $q, $localStorage, $timeout, $rootScope) {
    function TokenService() {
    };
    TokenService.prototype = {
        set: function (value) {
            return $timeout(function () {
                $window.sessionStorage.token = value;
                return $localStorage.set("token", value);
            });
        },
        get: function () {
            return $timeout(function () {
                if ($window.sessionStorage && $window.sessionStorage.token) return $window.sessionStorage.token;
                return $localStorage.get("token").then(function (value) {
                    if (!value) return $q.reject("token is empty");
                    return value;
                });
            });
        },
        reset: function () {
            return $timeout(function () {
                delete $window.sessionStorage.token;
                return $localStorage.remove("token");
            });
        }
    }
    return new TokenService();
} ]);
